package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import lombok.extern.slf4j.Slf4j;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {
    @Autowired
    private WmChannelService wmChannelService;

    /**
     * 查询所有频道
     *
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult getChannels() {
        //调用service
        return ResponseResult.okResult(wmChannelService.list());
    }

    /**
     * 条件分页查询频道信息
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult listChannel(@RequestBody ChannelDto dto) {
        log.info("平台管理后台条件查询展示所有频道信息...");

        return wmChannelService.listChannel(dto);
    }

    /**
     * 新增频道
     * @param wmChannel
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmChannel wmChannel){
        log.info("平台管理后新建频道:{}",wmChannel);

        return wmChannelService.insert(wmChannel);
    }

    /**
     * 根据id删除频道
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public ResponseResult delChannel(@PathVariable("id")Integer id){
        //调用service
        return wmChannelService.delChannel(id);
    }

    //修改频道
    @PostMapping("/update")
    public ResponseResult updateChannel(@RequestBody WmChannel dto){

        return wmChannelService.updateChannel(dto);
    }
}
